home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / pascal / gpc1.1p2 / gpc1 / usr / src / gpc-1.1p2-2.6.3 / gnuvers.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1995-04-20  |  2.2 KB  |  99 lines

  1. #! /bin/sh
  2. #
  3. # GNU version of BSD newvers.sh command
  4. #
  5. # Author: Jukka Virtanen <jtv@hut.fi>
  6. # Date:   Sat Aug 12 00:07:09 1989
  7. # Last modified: Thu Mar 23 22:18:13 1995
  8. #
  9. # Works in BSD & USG
  10. # reads an optional config file with additional %TOKEN% definitions.
  11. #
  12. # The second optional parameter is the protofile to use instead of
  13. # Version.c
  14. #
  15. # The optional configuration file name is given in the command line.
  16. #
  17. # The configuration file should contain a list of variable names in a
  18. # shell variable VARLIST
  19. #
  20. # All the variables in this list separated by '%' signs, e.g.
  21. #
  22. # VARLIST="FOO FOO2"
  23. # then all occurrences of %FOO% and %FOO2% are replaced by the values
  24. # of FOO and FOO2 correspondingly.
  25. #
  26.  
  27. if [ ! -r version ]; then
  28.   echo 0 > version
  29. fi
  30.  
  31. VERSIONPROTO=Version.c
  32.  
  33. VERSION=`cat version`
  34.  
  35. if [ -f /bin/hostname ]; then
  36.   HOST=`/bin/hostname`
  37. elif [ -f /bin/uname ]; then
  38.   HOST=`/bin/uname -n`
  39. else
  40.   HOST="unknown.host.name"
  41.   echo "$0: Unable to find out name of this host"
  42. fi
  43.  
  44. if [ -z "$USER" ]; then
  45.   USER=`whoami`
  46.   if [ -z "$USER" ]; then
  47.       USER="anonymous"
  48.       echo "$0: Unable to find out user name"
  49.   fi
  50. fi
  51.  
  52. DIR=`pwd`
  53. NOW=`date`
  54.  
  55. rm -f  version.c version.o
  56.  
  57. # Clear out the VARLIST variable
  58. VARLIST=
  59.  
  60. # Read in the contents of the optional config file
  61. if [ -f "$1" ]; then
  62.   . ./$1
  63. fi
  64.  
  65. # If the second argument exists, it is the protofile instead of ${VERSIONPROTO}
  66. if [ -f "$2" ]; then
  67.   VERSIONPROTO=$2
  68. fi
  69.  
  70. #
  71. # %VERSION%     includes DATE to be compatible with BSD newvers.sh
  72. # %VERSIONONLY% can be used to include version without DATE
  73. #
  74. sed -e "s^%WHOANDWHERE%^${USER}@${HOST}:${DIR}^" \
  75.     -e "s^%VERSION%^#${VERSION}: ${NOW}^"     \
  76.     -e "s^%WHO%^${USER}@${HOST}^"         \
  77.     -e "s^%WHERE%^${DIR}^"             \
  78.     -e "s^%DATE%^${NOW}^"             \
  79.     -e "s^%VARIABLE%^${VARIABLE}^"         \
  80.     -e "s^%VERSIONONLY%^#${VERSION}^"         \
  81.     ${VERSIONPROTO} > version.c
  82.  
  83. #
  84. # According to VARLIST set in the config file, edit the version.c
  85. #
  86. if [ -n "$VARLIST" ]; then
  87.  for var in $VARLIST; do
  88.   eval val=\${${var}}
  89.   sed -e "s^%$var%^$val^" version.c > /tmp/vers.$$
  90.   mv /tmp/vers.$$ version.c
  91.  done
  92. fi
  93.  
  94. # Actually, this is funny, because file version always contains the
  95. # next version, not the current one. This, too, is for compatibility.
  96. echo `expr ${VERSION} + 1` > version
  97.  
  98. exit 0
  99.